package com.xinqi.modules.course.clazz.controller.inner;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.course.clazz.client.ClassGroupClient;
import com.xinqi.modules.course.clazz.convert.ClassGroupConvert;
import com.xinqi.modules.course.clazz.domain.ClassGroupEntity;
import com.xinqi.modules.course.clazz.dto.rsp.ClassGroupResultDTO;
import com.xinqi.modules.course.clazz.manager.ClassGroupManager;
import com.xinqi.modules.course.clazz.service.ClassGroupService;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 班级分组表内部控制层
 *
 * @author: system
 * @date: 2023/10/31
 */
@Hidden
@Primary
@RestController
@RequiredArgsConstructor
public class ClassGroupInnerController implements ClassGroupClient {
    private final ClassGroupService classGroupService;
    private final ClassGroupManager classGroupManager;

    private final ClassGroupConvert classGroupConvert;

    @Override
    public R<ClassGroupResultDTO> findById(Long id) {
        ClassGroupResultDTO dto = classGroupService.findById(id);
        return R.data(dto);
    }

    @Override
    public R<List<ClassGroupResultDTO>> selectList(List<Long> groupIds) {
        LambdaQueryWrapper<ClassGroupEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(ClassGroupEntity::getId, groupIds);
        List<ClassGroupEntity> groups = classGroupManager.list(wrapper);
        return R.data(groups.stream().map(classGroupConvert::convert).collect(Collectors.toList()));
    }
}
